package com.success.application.shop;

import android.content.Intent;
import android.view.View;

import com.google.gson.reflect.TypeToken;
import com.success.application.api.YuanbaoApi;
import com.success.application.base.BaseRecyclerViewAdapter;
import com.success.application.base.BaseRecyclerViewFragment;
import com.success.application.common.param.Params;
import com.success.application.common.result.Result;
import com.success.application.myapplication.R;
import com.success.application.shop.activity.ActivityDetailActivity;
import com.success.application.shop.adapter.ActivityAdapter;
import com.success.application.shop.bean.HuoDong;
import com.success.application.test.TestAdapter;
import com.success.application.widget.SimplexToast;

import java.lang.reflect.Type;

/**
 * Created by Administrator on 2017/10/27.
 */

public class ActivityFragment extends BaseRecyclerViewFragment<HuoDong> {
    public static final String BUNDLE_KEY_HUODONG = "BUNDLE_KEY_HUODONG";
    public static final int REQUEST_CODE_MODIFY = 1; //点击活动详情
    private int mCurrentPosition;
    @Override
    protected BaseRecyclerViewAdapter<HuoDong> getRecyclerAdapter() {
        return new ActivityAdapter(mContext, BaseRecyclerViewAdapter.ONLY_FOOTER);
    }

    @Override
    protected Type getType() {
        return new TypeToken<Result<HuoDong>>() {
        }.getType();
    }
    @Override
    protected void initWidget(View root) {
        super.initWidget(root);
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    protected void requestData() {
        try {
            //获取参加活动列表
            Params P = new Params();
            P.put("count",10);
            P.put("pagenum",mPageNo);
            YuanbaoApi.getActivityList(P, mHandler);
        } catch (Exception e) {
            SimplexToast.show(mContext,"读取数据失败！");
            e.printStackTrace();
        }
    }
    @Override
    public void onItemClick(int position, long itemId) {
        //点击活动列表，打开活动详情页面
        this.mCurrentPosition = position;
        HuoDong huodong = mAdapter.getItem(position);
        Intent intent = new Intent(getActivity(), ActivityDetailActivity.class);
        intent.putExtra(BUNDLE_KEY_HUODONG, huodong);
        startActivityForResult(intent, REQUEST_CODE_MODIFY);
    }
}
